//
// Created by ZhangKewei on 2019/12/24.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <zconf.h>
#include "sysinfo.h"
#include "getsysinfo.h"

double mem_rate(){
    double mem_usage_rate = 0;
    meminfo();
    /*
     * 本程序算法为：
     * 内存总大小  = MemTotal的值
     * 空闲内存大小=	MemFree + Buffers + Cached
     * 内存使用率 = (MemTota – (MemFree+Buffers+Cached))/ MemTotal*100%
     */
    mem_usage_rate = ((double)kb_main_total - (double)(kb_main_free +
            kb_main_buffers + kb_main_cached))/(double)kb_main_total;
//    printf("mem_usage_rate = %.2lf%%\n",mem_usage_rate*100);
    return mem_usage_rate*100;

}



